using System;
using System.Text;
using InfoJetSoft.Service.XPath;

//CID 0164 //2008.12.13 //Begin
namespace InfoJetSoft.Service.XPath.Exprs
{
	/// <summary>
	/// Summary description for AbsoluteLocationPath.
	/// </summary>
    class AbsoluteLocationPath : IExpr
	{
        private OperatorExpr _start = null;
		private IExpr _relative = null;

		public AbsoluteLocationPath()
		{
			//
			// TODO: Add constructor logic here
			//
        }

        public object Evaluate(ExprContext context)
        {
            //CID 0815 //2011.03.01 //Begin
            object rootNode = context.Calculator.GetRootNode();
            INodeList contextNodes = context.Calculator.CreateNodeList();
            contextNodes.Append(rootNode);
            if (this._start.Operator == Operator.Slash)
            {
                context.Calculator.Slash(contextNodes);
            }
            else
            {
                context.Calculator.SlashSlash(contextNodes);
            }
            //CID 0958 //2011.06.21 //Begin
            if (this._relative != null)
            {
                return this._relative.Evaluate(context);
            }
            else
            {
                return context.Calculator.GetContextNodes(false);
            }
            //CID 0958 //2011.06.21 //End
            //CID 0815 //2011.03.01 //End
        }

        //CID 0866 //2011.04.01 //Begin
        public void Visit(IExprVisitor visitor)
        {
            this._start.Visit(visitor);
            this._relative.Visit(visitor);
        }
        //CID 0866 //2011.04.01 //End

        public void Print(StringBuilder buffer)
        {
            this._start.Print(buffer);
            if (this._relative != null)
            {
                this._relative.Print(buffer);
            }
        }

        public OperatorExpr Start
        {
            get
            {
                return this._start;
            }
        }

		public static IExpr Parse( ExprParser parser )
		{
            OperatorExpr stepSeparator = OperatorExpr.ParseStepSeparator(parser);
			if( stepSeparator != null )
			{
                AbsoluteLocationPath absoluteLocationPath = new AbsoluteLocationPath();
                absoluteLocationPath._start = stepSeparator;
                IExpr relativeLocationPath = RelativeLocationPath.Parse(parser);
				if( relativeLocationPath != null )
				{
					absoluteLocationPath._relative = relativeLocationPath;
				}
                return absoluteLocationPath;
			}
			return null;
		}
	}
}
//CID 0164 //2008.12.13 //End
